package com.www.dao.admin;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import org.springframework.stereotype.Repository;
import com.www.domain.admin.Checkin;

/**
 * 入住dao
 */
@Repository
public interface CheckinDao {
	/*
	 * 入住插入操作
	 */
	@Insert("insert into checkin(id,roomId,roomTypeId,checkinPrice,name,idCard,mobile,status,arriveDate,leaveDate,createTime,bookOrderId,remark) values(default,#{roomId},#{roomTypeId},#{checkinPrice},#{name},#{idCard},#{mobile},#{status},#{arriveDate},#{leaveDate},#{createTime},#{bookOrderId},#{remark})")
	public int add(Checkin checkin);
	
	/*
	 * 入住编辑操作
	 */
	@Update("update checkin set roomId = #{roomId},roomTypeId = #{roomTypeId},checkinPrice = #{checkinPrice},name = #{name},arriveDate = #{arriveDate},leaveDate = #{leaveDate},idCard = #{idCard},mobile = #{mobile},status = #{status},remark = #{remark} where id = #{id}")
	public int edit(Checkin checkin);
	
	/*
	 * 删除入住信息
	 */
	@Delete("delete from checkin where id = ${value}")
	public int delete(Long id);
	
	/*
	 * 入住信息搜索查询
	 */
	@Select({"<script> "+
			"select * from checkin " +
			"where 1=1 " +
			"<if test='name != null'> and name like '%${name}%'</if>" +
			"<if test='status != null'> and status like '%${status}%'</if>" +
			"<if test='roomId != null'> and roomId like '%${roomId}%'</if>" +
			"<if test='roomTypeId != null'> and roomTypeId like '%${roomTypeId}%'</if>" +
			"<if test='idCard != null'> and idCard like '%${idCard}%'</if>" +
			"<if test='mobile != null'> and mobile like '%${mobile}%'</if>" +
			"<if test='offset != null and pageSize != null'> limit #{offset},#{pageSize}</if>" +
	 		"</script>"})
	public List<Checkin> findList(Map<String, Object> queryMap);
	
	/*
	 * 模糊搜索总条数
	 */
	@Select({"<script>" +
			"select count(*) from book_order " +
			"where  1=1 " +
			"<if test='name != null'> and name like '%${name}%'</if>" +
			"<if test='status != null'> and status like '%${status}%'</if>" +
			"<if test='roomId != null'> and roomId like '%${roomId}%'</if>" +
			"<if test='roomTypeId != null'> and roomTypeId like '%${roomTypeId}%'</if>" +
			"<if test='idCard != null'> and idCard like '%${idCard}%'</if>" +
			"<if test='mobile != null'> and mobile like '%${mobile}%'</if>" +
			"</script>"})
	public Integer getTotal(Map<String, Object> queryMap);
	
	/*
	 * 获取单个入住信息
	 */
	@Select("select * from checkin where id = #{value}")
	public Checkin find(Long id);
	
	/*
	 * 按月获取统计信息
	 */
	@Select("select sum(checkinPrice) as money,DATE_FORMAT(createTime,'%Y-%m') as stats_date from checkin GROUP BY DATE_FORMAT(createTime,'%Y-%m')")
	public List<Map> getStatsByMonth();
	
	/*
	 * 按日获取统计信息
	 */
	@Select("select sum(checkinPrice) as money,DATE_FORMAT(createTime,'%Y-%m-%d') as stats_date from checkin GROUP BY DATE_FORMAT(createTime,'%Y-%m-%d')")
	public List<Map> getStatsByDay();
}
